<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<portlet:defineObjects/>

<script type="text/javascript" src="<%=renderRequest.getContextPath()%>/lightbox2.02/js/prototype.js"></script>
<script type="text/javascript" src="<%=renderRequest.getContextPath()%>/lightbox2.02/js/scriptaculous.js?load=effects"></script>
<script type="text/javascript" src="<%=renderRequest.getContextPath()%>/lightbox2.02/js/lightbox.js"></script>

<link rel="stylesheet" href="<%=renderRequest.getContextPath()%>/lightbox2.02/css/lightbox.css" type="text/css" media="screen" />

<script language="javascript">
    function confirmAction(msg, link) {
    var ans = confirm(msg);
    if (ans == true) {
    return true;
    } else {
    return false;
    }
    }            
</script>

<c:choose>
<c:when test="${!(fn:length(photosBean.photos) == 0)}">
<table class="<portlet:namespace/>-photos">
<thead>
    <tr>
        <th>
            <table class="<portlet:namespace/>-photocount">
                <tr>
                    <td class="<portlet:namespace/>-left">
                        <fmt:message key="photos">
                            <fmt:param value="${photosBean.firstPhotoNumber}"/>
                            <fmt:param value="${photosBean.lastPhotoNumber}"/>
                            <fmt:param value="${photosBean.total}"/>
                        </fmt:message>
                    </td>
                    <c:if test="${authHandler.authenticated && pageHander.myPage}">
                        <td class="<portlet:namespace/>-right">
                            <portlet:actionURL var="addPageAction">
                                <portlet:param name="action" value="navigate-add"/>
                            </portlet:actionURL>                                
                            <a href="${pageScope['addPageAction']}">
                                <img src="<%=renderRequest.getContextPath()%>/images/add.png" class="<portlet:namespace/>-icon"/>                
                                <fmt:message key="add"/>
                            </a>
                        </td>
                    </c:if>
                </tr>
            </table>
        </th>
    </tr>
</thead>
<tbody>
<tr>
<td class="<portlet:namespace/>-left">
<c:set var="i" value="0"/>
<c:forEach var="photo" items="${photosBean.photos}">
<portlet:actionURL var="deleteAction">
    <portlet:param name="action" value="delete"/>
    <portlet:param name="id" value="${photo.photoId}"/>                                            
</portlet:actionURL>
<div class="<portlet:namespace/>-photo <portlet:namespace/>-hovered">
<c:set var="title" value="${photo.title}"/>
<a href="<c:out value="${photo.mediumUrl}"/>" rel="lightbox[flickrportlet]" title="<c:out value="${title}"/>">
    <img src="<c:out value="${photo.smallSquareUrl}"/>"/>
     </a>
<br/>
<c:if test="${authHandler.authenticated && pageHandler.myPage}">        
<a href="${pageScope['deleteAction']}" 
   onclick="return confirm('<fmt:message key="confirmDelete"><fmt:param value="${photo.title}"/></fmt:message>')">
    <span style="text-size: smaller"><fmt:message key="delete"/></span>
</a>
</c:if>
</div>
<c:set var="i" value="${i+1}"/>
</c:forEach>
</td>
</tr>                
</tbody>
<tfoot>
    <tr>
        <th>
            <table>
                <tr>
                    <c:choose>
                        <c:when test="${!(photosBean.page == 1)}">
                            <td>
                                <portlet:actionURL var="previousPageAction">
                                    <portlet:param name="action" value="previous-page"/>
                                </portlet:actionURL>
                                <a href="${pageScope['previousPageAction']}">
                                    <img src="<%=renderRequest.getContextPath()%>/images/rewind.png" style="border-width: 0px"/>
                                </a>
                            </td>
                        </c:when>
                        <c:otherwise>
                            <td>
                                <img src="<%=renderRequest.getContextPath()%>/images/rewind-disabled.png" style="border-width: 0px"/>                
                            </td>
                        </c:otherwise>
                    </c:choose>
                    <td>
                        <fmt:message key="pages">
                            <fmt:param value="${photosBean.page}"/>
                            <fmt:param value="${photosBean.pages}"/>                    
                        </fmt:message>
                        <c:out value=":"/>
                        <c:forEach var="i" begin="1" end="${photosBean.pages}">
                            <portlet:actionURL var="gotoPageAction">
                                <portlet:param name="action" value="goto-page"/>
                                <portlet:param name="page" value="${i}"/>
                            </portlet:actionURL>
                            <c:choose>
                                <c:when test="${i == photosBean.page}">
                                    &nbsp<span style="font-weight: bold"><c:out value="${i}"/></span>
                                </c:when>
                                <c:otherwise>
                                    &nbsp;<a href="${pageScope['gotoPageAction']}"><c:out value="${i}"/></a>
                                </c:otherwise>
                            </c:choose>
                        </c:forEach>
                    </td>
                    <c:choose>
                        <c:when test="${photosBean.morePages}">
                            <td>
                                <portlet:actionURL var="nextPageAction">
                                    <portlet:param name="action" value="next-page"/>
                                </portlet:actionURL>
                                <a href="${pageScope['nextPageAction']}">
                                    <img src="<%=renderRequest.getContextPath()%>/images/forward.png" class="<portlet:namespace/>-icon"/>
                                </a>
                            </td>
                        </c:when>
                        <c:otherwise>
                            <td>
                                <img src="<%=renderRequest.getContextPath()%>/images/forward-disabled.png" class="<portlet:namespace/>-icon"/>                
                            </td>
                        </c:otherwise>
                    </c:choose>
                </tr>
            </table>
        </th>
    </tr>
</tfoot>
</table>
</c:when>
<c:otherwise>
    <fmt:message key="noPhotos"/>
</c:otherwise>
</c:choose>
